/*
 * @Author: silence
 * @Date: 2022-05-28 11:32:05
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2023-03-14 13:25:11
 * @Description: qq客服 、qq群
 */

import 'dart:io';

import 'package:flutter/material.dart';
import 'package:sil_base_widget_package/sil_base_widget_package.dart';
import 'package:url_launcher/url_launcher.dart';

/**
 * @description: 到qq客服
 * @return {*}
 */
gotoQQServer(BuildContext context, String? qqNumber) async {
  String qqServerNumber = qqNumber ?? '3481702894';
  String url;
  if (Platform.isAndroid) {
    url =
        'mqqwpa://im/chat?chat_type=wpa&uin=$qqServerNumber&version=1&src_type=web&web_src=http:://wpa.b.qq.com';
  } else {
    url =
        'mqq://im/chat?chat_type=wpa&uin=$qqServerNumber&version=1&src_type=web';
  }

  Uri uri = Uri.parse(url);
  if (await canLaunchUrl(uri)) {
    await launchUrl(uri);
  } else {
    SilAlertDialog.showAlertDialog(
        context,
        SilAlertDialogData(
            title: '温馨提示', content: "请安装QQ客户端", confrimButtonTitle: '确定'));
  }
}

/**
 * @description: 加入群聊
 * @return {*}
 */
gotoQQGroup(BuildContext context, String qqGroupNNumber) async {
  String url;
  if (Platform.isAndroid) {
    url =
        "mqqapi://card/show_pslcard?src_type=internal&version=1&uin=$qqGroupNNumber&key=44a6e01f2dab126f87ecd2ec7b7e66ae259b30535fd0c2c25776271e8c0ac08f&card_type=group&source=external";
  } else {
    url =
        "mqqapi://card/show_pslcard?src_type=internal&version=1&uin=$qqGroupNNumber&key=44a6e01f2dab126f87ecd2ec7b7e66ae259b30535fd0c2c25776271e8c0ac08f&card_type=group&source=external";
  }

  Uri uri = Uri.parse(url);
  if (await canLaunchUrl(uri)) {
    await launchUrl(uri);
  } else {
    SilAlertDialog.showAlertDialog(
        context,
        SilAlertDialogData(
            title: '温馨提示', content: "请安装QQ客户端", confrimButtonTitle: '确定'));
  }
}
